﻿using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;

namespace MinaspetroLibrary.ObrigacoesPack
{
    [Serializable()]
    public class ObrigacoesChildInfo : Csla.ReadOnlyBase<ObrigacoesChildInfo>
    {
        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private String _titulo = String.Empty;

        private String _periodo = String.Empty;

        private String _pagamento = String.Empty;

        private String _observacao = String.Empty;

        private String _descricao = String.Empty;

        private DateTime _dataCadastro = DateTime.Now;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }

        public String Titulo
        {
            get
            {
                return _titulo;
            }
        }

        public String Periodo
        {
            get
            {
                return _periodo;
            }
        }

        public String PeriodoString
        {
            get
            {
                if (_periodo.Contains("_"))
                    return _periodo.Substring(_periodo.IndexOf("_") + 1);
                return _periodo;
            }
        }

        public String Pagamento
        {
            get
            {
                return _pagamento;
            }
        }

        public String Observacao
        {
            get
            {
                return _observacao;
            }
        }

        public String Descricao
        {
            get
            {
                return _descricao;
            }
        }

        public DateTime DataCadastro
        {
            get
            {
                return _dataCadastro;
            }
        }

        public String DataCadastroShortString
        {
            get
            {
                return _dataCadastro.ToString("dd/MM/yyyy");
            }
        }

        public String DataCadastroFullString
        {
            get
            {
                return _dataCadastro.ToString("dd/MM/yyyy HH:mm");
            }
        }

        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static ObrigacoesChildInfo GetObrigacoesChildInfo(SafeDataReader dr)
        {
            return new ObrigacoesChildInfo(dr);
        }

        private ObrigacoesChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region DataCadastro Access

        #region DataCadastro Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString());
            _titulo = dr.GetString("Titulo");
            _periodo = dr.GetString("Periodo");
            _pagamento = dr.GetString("Pagamento");
            _observacao = dr.GetString("Observacao");
            _descricao = dr.GetString("Descricao");
            _dataCadastro = dr.GetDateTime("DataCadastro");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //DataCadastro Access - Fetch
        #endregion //DataCadastro Access
    }
}
